<%--
  Created by IntelliJ IDEA.
  User: 14811
  Date: 2022-5-1
  Time: 9:50
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@include file="/common/common.jsp"%>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>收藏排行榜</title>
    <link rel="stylesheet" type="text/css" href="<%=path%>/css/common.css">
    <link rel="stylesheet" type="text/css" href="<%=path%>/css/ranking-list.css">
</head>
<body>
<!--引入头部-->
<jsp:include page="header.jsp"/>
<div class="contant">
    <div class="shaixuan">
        <span>线路名称</span>
        <input type="text" name="rname" id="rname">
        <span>金额</span>
        <input type="text" value="price">~<input type="text" value="price">
        <button onclick="findCollectRoute()">搜索</button>
    </div>
    <div class="list clearfix">
        <ul>
            <c:forEach items="${pageInfo}" var="route" varStatus="s">
                <li>
                    <span class="num one" id="count">${s.count}</span>
                    <a href="<%=path%>/pageController/toRouteDetail/${route.rid}/${route.sid}"><img src="<%=path%>/file/download?filename=${route.rimage}" alt="" width="170px" height="140px"></a>
                    <h4><a href="<%=path%>/pageController/toRouteDetail/${route.rid}/${route.sid}">${route.rname}</a></h4>
                    <p>
                        <b class="price">&yen;<span>${route.price}</span>起</b>
                        <span class="shouchang">已收藏${route.count}次</span>
                    </p>
                </li>
            </c:forEach>

        </ul>
    </div>
<%--    <h3>当前第页</h3>--%>
    <%--<div class="page_num_inf" id="page_num_inf">
        <h4>共${pageInfo.pages}页！当前第${pageInfo.pageNum}页</h4>
        <nav aria-label="Page navigation">
            <ul class="pagination">
                <li>
                    <a href="${pageContext.request.contextPath}/pageController/toFavoriteRank?pageNum=${pageInfo.pageNum-1}&pageSize=8" aria-label="Previous">
                        <span aria-hidden="true">&laquo;</span>
                    </a>
                </li>
                <c:forEach begin="1" end="${pageInfo.pages}" var="i" >
                    <li><a href="${pageContext.request.contextPath}/pageController/toFavoriteRank?pageNum=${i}&pageSize=8">${i}</a></li>
                </c:forEach>
                <li>
                    <a href="${pageContext.request.contextPath}/pageController/toFavoriteRank?pageNum=${pageInfo.pageNum+1}&pageSize=8" aria-label="Next">
                        <span aria-hidden="true">&raquo;</span>
                    </a>
                </li>
            </ul>
        </nav>
    </div>--%>
    <div id="test">

    </div>

</div>

<!--导入底部-->
<div id="footer">
    <jsp:include page="footer.jsp"/>
</div>
<!--导入布局js，共享header和footer-->
</body>
</html>
<script>
    $(function () {
        favoriteRankAll();
    })

    function favoriteRankAll() {
        var num = ${pageNum};
        $.ajax({
            url:"<%=path%>/pageController/favoriteRankPage",
            type:"post",
            dataType:"json",
            success:function (data) {
                console.log(data)
                /*for (var i = 0; i < data.total; i++) {
                    $("#count").html(i);
                }*/
                var pages = data.pages;
                // alert(pages)
                var str = "<h4>一共"+ data.pages +"页,"+ data.total +"条,";
                str +="当前第${pageNum}页</h4>";
                str +="<nav aria-label='Page navigation'>";
                str +="<ul class='pagination'>";
                if (num===1){
                    toastr.error("当前第一页");
                    str +="<li><a id='previous' href='#' aria-label='Previous'> <span aria-hidden='true'>&laquo; </a></span>" + "</li>";
                }else {
                    str +="<li><a id='previous' href='${pageContext.request.contextPath}/pageController/toFavoriteRank?pageNum=${pageNum-1}' aria-label='Previous'> <span aria-hidden='true'>&laquo; </a></span>" + "</li>";
                }
                var route = data.list;
                for (var i = 1; i <= data.pages; i++) {
                    str +="<li><a href='${pageContext.request.contextPath}/pageController/toFavoriteRank?pageNum="+i+"'>"+i+"</a></li>"
                }
                if (num===(parseInt(pages))){
                    toastr.error("当前最后一页");
                    str +="<li><a id='previous' href='#' aria-label='Next'> <span aria-hidden='true'>&raquo; </a></span>" + "</li>";
                }else {
                    str +="<li><a href='${pageContext.request.contextPath}/pageController/toFavoriteRank?pageNum=${pageNum+1}' aria-label='Next'> <span aria-hidden='true'>&raquo;</span> </a>" + "</li>";
                }


                $("#test").html(str)
            },
            error:function () {
                alert("错误")
            }
        })
    }

    function findCollectRoute() {
        var input = $("#test").val();
    }
</script>
